module Maze
  module TextFormatter
    module DrawingHelpers
      def to_s
        canvas.map { |line| line.join }.join("\n")
      end

      alias_method :draw, :to_s

      def canvas_draw
        maze.height.times do |y|
          maze.width.times do |x|
            canvas_update Point.new(x, y)
          end
        end
      end

      def canvas_update(for_point)
        origin =  calculate_origin(for_point)

        maze.directions.each do |direction|
          offset = origin + calculate_offset(direction, for_point)

          unless maze.connected?(for_point, direction)
            canvas[offset.y][offset.x] = select_character(direction)
          end
        end
      end
    end
  end
end
